package com.ruoyi.handler.socket;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MySocketChannelInboundHandler8083 extends ChannelInboundHandlerAdapter {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        Channel channel = ctx.channel();
        log.info("8083端口的RTK设备连接成功, channel: {}", channel);

        super.channelActive(ctx);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        Channel channel = ctx.channel();

        log.info("channelRead msg: {}", msg);
        ByteBuf msgBuf = (ByteBuf) msg;
//        log.info("<========打印接收到的字节码===========>");
//        ByteBufUtil.logByteBuf(msgBuf);
        log.info("8083端口接收到RTK设备的报文，channel: {},报文长度: {}", channel, msgBuf.readableBytes());

        MySocketChannelInboundHandler9083.sendMsgToAllOnlineChannel(msgBuf);

        super.channelRead(ctx, msg);
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        Channel channel = ctx.channel();
        log.info("8083端口的RTK设备断开连接, channel: {}", channel);

        super.channelInactive(ctx);
    }
}
